home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / fileutil.zip / CP-AUX.C < prev    next >
C/C++ Source or Header  |  1992-02-22  |  5KB  |  167 lines

  1. /*  cp-aux.c  -- file copying (auxiliary routines)
  2.     Copyright (C) 1989, 1990 Free Software Foundation.
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 1, or (at your option)
  7.     any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     Written by Torbjorn Granlund, Sweden (tege@sics.se).
  19. */
  20.  
  21. /*  MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  22.     This port is also distributed under the terms of the
  23.     GNU General Public License as published by the
  24.     Free Software Foundation.
  25.  
  26.     Please note that this file is not identical to the
  27.     original GNU release, you should have received this
  28.     code as patch to the official release.
  29.  
  30.     $Header: e:/gnu/fileutil/RCS/cp-aux.c 1.4.0.2 90/09/19 11:18:11 tho Exp $
  31.  */
  32.  
  33. #include <stdio.h>
  34.  
  35. #include "cp.h"
  36.  
  37. extern char *program_name;
  38.  
  39. void
  40. usage (reason)
  41.      char *reason;
  42. {
  43.   if (reason != NULL)
  44.     fprintf (stderr, "%s: %s\n", program_name, reason);
  45.  
  46. #ifdef MSDOS
  47.   fprintf (stderr, "\
  48. Usage: %s [-bdfipruvxR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  49.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  50.        [+preserve] [+recursive] [+update] [+verbose] [+suffix backup-suffix]\n\
  51.        [+version-control {numbered,existing,simple}] [+copying] [+version]\n\
  52.        source dest\n\
  53. \n\
  54.        %s [-bdfipruvxR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  55.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  56.        [+preserve] [+recursive] [+update] [+verbose] [+suffix backup-suffix]\n\
  57.        [+version-control {numbered,existing,simple}] [+copying] [+version]\n\
  58.        source... directory\n",
  59.        program_name, program_name);
  60. #else /* not MSDOS */
  61.   fprintf (stderr, "\
  62. Usage: %s [-bdfipruvxR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  63.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  64.        [+preserve] [+recursive] [+update] [+verbose] [+suffix backup-suffix]\n\
  65.        [+version-control {numbered,existing,simple}] source dest\n\
  66. \n\
  67.        %s [-bdfipruvxR] [-S backup-suffix] [-V {numbered,existing,simple}]\n\
  68.        [+backup] [+no-dereference] [+force] [+interactive] [+one-file-system]\n\
  69.        [+preserve] [+recursive] [+update] [+verbose] [+suffix backup-suffix]\n\
  70.        [+version-control {numbered,existing,simple}] source... directory\n",
  71.        program_name, program_name);
  72. #endif /* not MSDOS */
  73.  
  74.   exit (2);
  75. }
  76.  
  77. /* Use the one from gnulib */
  78. #ifndef MSDOS
  79.  
  80. char *
  81. xmalloc (size)
  82.      unsigned size;
  83. {
  84.   char *x = malloc (size);
  85.   if (x == 0)
  86.     error (1, 0, "virtual memory exhausted");
  87.   return x;
  88. }
  89.  
  90. char *
  91. xrealloc (ptr, size)
  92.      char *ptr;
  93.      unsigned size;
  94. {
  95.   char *x = realloc (ptr, size);
  96.   if (x == 0)
  97.     error (1, 0, "virtual memory exhausted");
  98.   return x;
  99. }
  100.  
  101. #endif /* not MSDOS */
  102.  
  103. char *
  104. stpcpy (s1, s2)
  105.      char *s1;
  106.      char *s2;
  107. {
  108.   while ((*s1++ = *s2++) != '\0')
  109.     ;
  110.   return s1 - 1;
  111. }
  112.  
  113. int
  114. yesno ()
  115. {
  116.   int c, t;
  117.  
  118.   fflush (stderr);
  119.   c = t = getchar ();
  120.   while (t != EOF && t != '\n')
  121.     t = getchar ();
  122.   return c == 'y' || c == 'Y';
  123. }
  124.  
  125.  
  126. #ifndef MSDOS            /* no links ... */
  127.  
  128. int
  129. is_ancestor (sb, ancestors)
  130.      struct stat *sb;
  131.      struct dir_list *ancestors;
  132. {
  133.   while (ancestors != 0)
  134.     {
  135.       if (ancestors->ino == sb->st_ino && ancestors->dev == sb->st_dev)
  136.     return 1;
  137.       ancestors = ancestors->parent;
  138.     }
  139.   return 0;
  140. }
  141.  
  142.  
  143. /* Remove trailing slashes from PATH; they cause some system calls to fail. */
  144.  
  145. void
  146. strip_trailing_slashes (path)
  147.      char *path;
  148. {
  149.   int last;
  150.  
  151.   last = strlen (path) - 1;
  152.   while (last > 0 && path[last] == '/')
  153.     path[last--] = '\0';
  154. }
  155.  
  156. #else /* MSDOS */
  157.  
  158. void
  159. strip_trailing_slashes (char **path)
  160. {
  161.   char *new_path = _fullpath (NULL, *path, 0);
  162.   free (*path);
  163.   *path = msdos_format_filename (new_path);
  164. }
  165.  
  166. #endif /* MSDOS */
  167.